import 'package:flutter/cupertino.dart' as cup;
import 'package:flutter/material.dart';
import '../../../common/utils/shortcut.dart';
import '../../../common/utils/i18n.dart';
import '../../../config.dart';
import '../../resources/resources.dart';
import '../my_div.dart';
import '../my_text.dart';

class MyActionSheetAction {
  final String text;
  final Color? textColor;
  final double? fontSize;
  final bool bold;
  final VoidCallback onTap;

  const MyActionSheetAction({
    required this.text,
    this.textColor,
    required this.onTap,
    this.fontSize,
    this.bold = false,
  });

  // factory MyActionSheetAction.cancel({VoidCallback? onTap}) {
  //   return MyActionSheetAction(
  //       text: "取消",
  //       onTap: onTap ??
  //           () {
  //             back();
  //           },
  //       bold: true);
  // }
  factory MyActionSheetAction.delete({required VoidCallback onTap}) {
    return MyActionSheetAction(
      text: "删除",
      textColor: Colors.red,
      onTap: onTap,
    );
  }

  factory MyActionSheetAction.confirm({required VoidCallback onTap}) {
    return MyActionSheetAction(
      text: "确定",
      onTap: onTap,
    );
  }
}

class MyActionSheet extends StatelessWidget {
  final List<MyActionSheetAction> actions;

  final String? title;
  final String? content;
  final bool cancelButton;
  const MyActionSheet(
      {super.key,
      required this.actions,
      this.title,
      this.content,
      this.cancelButton = true});

  @override
  Widget build(BuildContext context) {
    return cup.CupertinoActionSheet(
      title: title != null ? cup.Text(title!) : null,
      message: content != null ? cup.Text(content!) : null,
      actions: actions
          .map((e) => cup.CupertinoActionSheetAction(
                onPressed: e.onTap,
                child: cup.Text(
                  e.text.i18n,
                  style: cup.TextStyle(
                    color: e.textColor ?? defaultColor,
                    fontSize: e.fontSize,
                    fontWeight: e.bold ? FontWeight.bold : FontWeight.normal,
                  ),
                ),
              ))
          .toList(),
      cancelButton: cancelButton
          ? cup.CupertinoActionSheetAction(
              onPressed: () {
                back();
              },
              child: cup.Text(
                "取消".i18n,
                style: const cup.TextStyle(
                  fontWeight: FontWeight.bold,
                  color: Color(0xff007AFF),
                ),
              ),
            )
          : null,
    );
  }

  Future<T?> show<T>({bool isDismissible = true}) {
    return openBottomSheet(this, isDismissible: isDismissible);
  }
}
